const Mock = require('mockjs')

const List = []

const data = Mock.mock({
  'items|2': [{
    'id|+1': 1,    //id
    roleCode: 'U123',     //角色编号
    'roleName|+1':['管理员','普通用户'],    //角色名称
    'roleState|1': ['启用','禁用']      //用户状态
  }]
})

// List = items
for(let i=0;i < data.items.length;i++){
  List.push(data.items[i])
}

module.exports = [
  // 获取用户角色列表
  {
    url: '/vue-admin-template/userRole/list',
    type: 'get',
    response: config => {
      const items = data.items
      return {
        code: 20000,
        data: {
          total: items.length,
          items: items
        }
      }
    }
  },

  //新增用户角色
  {
    url:'/vue-element-template/userRole/add',
    type:'post',
    response: _ =>{
      return{
        code: 20000,
        data: 'success'
      }
    }
  },
  //修改用户角色
  {
    url:'/vue-element-template/userRole/edit',
    type:'post',
    response: _ =>{
      return{
        code: 20000,
        data: 'success'
      }
    }
  },
  //查询用户角色
  {
    url: '/vue-element-template/userRole/find',
    method: 'get',
    response:config =>{
      const {roleCode,roleName,roleState} = config.query
      //list方法筛选
      // let mockList = List.filter(item =>{
      //   if(userCode&&item.userCode !== item.userCode) return false
      //   if(userGender&&item.userGender !==item.userGender) return false
      //   if(userName&&item.userName !== item.userName) return false
      //   if(userRole !== item.userRole) return false
      //   if(userState !== item.userState) return false
      //   return true 
      // })
      let mockList = List.filter(function(x){
        // return x.userCode === userCode
        return x.roleCode == roleCode||x.roleName === roleName||
               x.roleState === roleState
      })

      // if(userCode === null&&userName===null&&userGender===null&&userRole==null&&userState==null){

      // }

      return{
        code: 20000,
        data:{
          total:mockList.length,
          items:mockList
          // items
        }
      }
    }
  },
]
